/**
 * Created by Esri on 2016/6/28.
 */
define([ "dojo/_base/declare",
        "gistech/widgets/baseWidget/BaseWidget",
        "dojo/_base/lang",
        "dojo/on",
        "dojo/dom-construct",
        "dojo/query",
        "dojo/dom-style",
        "dojo/dom-class",
        "dojo/dom-attr",
        "dojo/topic",
        "dojo/text!./templates/Template.html"],
    function(declare,BaseWidget,lang,on,domConstruct,query, 
    		domStyle,domClass,domAttr,topic,template) {
	
        return declare([BaseWidget], {
            templateString : template,
            map:null,
            isopen:false,
            
            constructor : function(args) {
                this.inherited(arguments);
                this.map=args.map;
                this.gOtherLayer = this.map.getLayer("other");
                this.container = args.container;
            },
            
            postCreate : function() {
            	this.init();
                this.bindEvent();
                this.inherited(arguments);
            },
            
            startup:function(){
                this.inherited(arguments);
            },
            
            destroy:function(){
                this.inherited(arguments);
            },
            
            init:function(){
            	domConstruct.place(this.domNode, this.container);
            },
            
            bindEvent:function(){
            	topic.subscribe("showDrawGreaphic", lang.hitch(this, this.toggleToolBox));
            },
            
            MapBtnClick:function(){
            	alert("MapBtnClick");
            },
            
            DrawBtnClick:function(){
            	topic.publish("showDrawGreaphic", '');
            },
            
            TopBtnClick:function(){
            	alert("TopBtnClick");
            },
            
            ToolBtnClick:function(){
            	alert("ToolBtnClick");
            },
            
            toggleToolBox:function(){
            	//dojo.query(".drawGraphic");
            	if(this.isopen){
            		this.hideBox();
            	}else{
            		domClass.remove(this.domNode, "hiddenGraphicanimation");
            		domClass.add(this.domNode, "showGraphicanimation");
                	this.isopen=!this.isopen;
            	}
            },
            
            //隐藏画图形状选择box
            hideBox:function(){
            	domClass.remove(this.domNode, "showGraphicanimation");
        		domClass.add(this.domNode, "hiddenGraphicanimation");
        		this.isopen=!this.isopen;
        		if(Global.QueryInfoWindow!=null){
           		    this.map.infoWindow.hide();//先隐藏其他infowindow
        			if(Global.contentInfoWin!=null){
                		Global.contentInfoWin.destroy();
                		Global.contentInfoWin=null;
        			}
           		    Global.SelectGraphic=null;
        		}
        		this.removeFeatureFromMap();
            },
            
            //删除feature
    		removeFeatureFromMap:function(){
    			for (var i = this.gOtherLayer.graphics.length - 1; i >= 0; i--) {
                    var temGraphic =this.gOtherLayer.graphics[i];
                    if (temGraphic != null && temGraphic != undefined && temGraphic.bType == "ExtendQuery") {
                    	if (Global.SelectGraphic==temGraphic){
                        	//this.map.infoWindow.hide();
                        	Global.SelectGraphic=null;
                        }
                    	this.gOtherLayer.remove(temGraphic);
                    }
                }
    		},
            
        })
    }
);